export default function Tank(top_, left_, campClass_, tankMove_, tankFire_, camp_) {
     this.top = top_
     this.left = left_
     this.moving = false
     this.direction = "right"
     this.campClass = campClass_
     this.camp = camp_
     this.direcClass = " turnRight"
     this.tankMove = tankMove_
     this.tankFire = tankFire_
     this.alive = true

     this.startMoveLeft = function(){
         if(this.moving){return}
        this.moving = true
        this.direcClass = " turnLeft"
        this.direction = "left"
         if(this.camp=="mine"){
         this.tankMove.play()
         }
    }

    this.startMoveRight= function(){
        if(this.moving){return}
        this.moving = true
        this.direcClass = " turnRight"
        this.direction = "right"
        if(this.camp=="mine"){
            this.tankMove.play()
        }
    }

    this.startMoveUp= function(){
        if(this.moving){return}
        this.moving = true
        this.direcClass = " turnUp"
        this.direction = "up"
        if(this.camp=="ming") {
            this.tankMove.play()
        }
    }

    this.startMoveDown= function(){
        if(this.moving){return}
        this.moving = true
        this.direcClass = " turnDown"
        this.direction = "down"
        if(this.camp=="mine") {
            this.tankMove.play()
        }
    }

    this.stopMove= function(){
        this.moving = false
        if(this.camp=="mine") {
            this.tankMove.pause()
        }
    }
    this.die = function(){
      this.stopMove()
      this.alive = false
    }

    this.shoot= function(){
        if(this.camp=="mine") {
            this.tankFire.currentTime = 0
            this.tankFire.play()
        }
        let num = new Date().getTime()
        if(this.direction=='left'){
            return {top: this.top + 1.75, left: this.left, class:'bulletLeft', direction:this.direction, camp:this.camp, id:num}
        }else if(this.direction=='right'){
            return {top: this.top + 1.75, left: this.left + 4, class:'bulletRight', direction:this.direction, camp:this.camp, id:num}
        }else if(this.direction=='up'){
            return {top: this.top - 1, left: this.left + 1.75, class:'bulletUp', direction:this.direction, camp:this.camp, id:num}
        }else if(this.direction=='down'){
            return {top: this.top + 4, left: this.left + 1.75, class:'bulletDown', direction:this.direction, camp:this.camp, id:num}
        }
    }
}
